package MyExcelTool;

import jxl.Sheet;
import jxl.write.Label;
import jxl.write.WritableCellFormat;
import jxl.write.WritableSheet;
import jxl.write.WriteException;
import jxl.write.biff.RowsExceededException;

public class BaseTemplate {
	private WritableSheet ws=null;
	private WritableCellFormat format=null;
	private Sheet sheet=null;
	
	public final int COL_LENGTH=8;
	public final int ROW_LENGTH=225;

	public void setFormat(WritableCellFormat format) {
		this.format = format;
	}
	
	public void setWs(WritableSheet ws) {
		this.ws = ws;
	}

	public WritableSheet getWs() {
		return ws;
	}
	
	public WritableCellFormat getFormat() {
		return format;
	}
	

	public Sheet getSheet() {
		return sheet;
	}

	public void setSheet(Sheet sheet) {
		this.sheet = sheet;
	}

	/**
	 * 
	 * @param ws WritableSheet
	 * @param format WritableCellFormat
	 * @param arg0 The String You Want to Insert
	 * @param start_x The X pos of the Start Cell 
	 * @param start_y The Y pos of the Start Cell
	 * @param end_x The X pos of the End Cell
	 * @param end_y The Y pos of the End Cell
	 */
	protected void addCell(
			String arg0, int start_x, int start_y, int end_x, int end_y) {
		try {
			addCell(arg0, start_x, start_y);
			ws.mergeCells(start_x, start_y, end_x, end_y);
		} catch (RowsExceededException e) {
			e.printStackTrace();
		} catch (WriteException e) {
			e.printStackTrace();
		}
	}
	/**
	 * 
	 * @param ws WritableSheet
	 * @param format WritableCellFormat
	 * @param arg0 The String You Want to Insert
	 * @param start_x The X pos of the Start Cell 
	 * @param start_y The Y pos of the Start Cell
	 */
	protected void addCell(
			String arg0, int start_x, int start_y) {
		try {
			ws.addCell(new Label(start_x, start_y, arg0, format));
		} catch (RowsExceededException e) {
			e.printStackTrace();
		} catch (WriteException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 
	 * @param ws WritableSheet
	 * @param format WritableCellFormat
	 * @param arg0 The Number You Want to Insert
	 * @param start_x The X pos of the Start Cell 
	 * @param start_y The Y pos of the Start Cell
	 */
	protected void addNumber(
			double arg0, int start_x, int start_y) {
		try {
			ws.addCell(new jxl.write.Number(start_x, start_y, arg0, format));
		} catch (RowsExceededException e) {
			e.printStackTrace();
		} catch (WriteException e) {
			e.printStackTrace();
		}
	}
	

	/**
	 * 
	 * @param ws WritableSheet
	 * @param format WritableCellFormat
	 * @param arg0 The Number You Want to Insert
	 * @param start_x The X pos of the Start Cell 
	 * @param start_y The Y pos of the Start Cell
	 * @param end_x The X pos of the End Cell
	 * @param end_y The Y pos of the End Cell
	 */
	protected void addNumber(
			double arg0, int start_x, int start_y, int end_x, int end_y) {
		try {
			addNumber(arg0, start_x, start_y);
			ws.mergeCells(start_x, start_y, end_x, end_y);
		} catch (RowsExceededException e) {
			e.printStackTrace();
		} catch (WriteException e) {
			e.printStackTrace();
		}
	}
	
	protected String getCell(int start_x, int start_y){
		return sheet.getCell(start_x, start_y).getContents();
	}
	
	protected float getFloat(int start_x,int start_y){
		String cellValue=sheet.getCell(start_x, start_y).getContents();
		float value=0.0f;
		try{
			value=Float.parseFloat(cellValue);
		}catch (Exception e) {
			value=0.0f;
		}
		
		return value;
	}
	
	protected double roundscale(double d, int scale) {
        long temp=1;
        for (int i=scale; i>0; i--) {
                temp*=10;
        }
        d*=temp;
        long dl=Math.round(d);
        return (double)(dl)/temp;
  }
	
	public static final String XIANXIAN5="qualitylevel.Xianxian5";
	public static final String XIANXIAN1="qualitylevel.Xianxian1";
	public static final String BUDGETEXCEL="exltemplate.BudgetExcel";


}
